package com.wicket.okrapp.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wicket.okrapp.common.dto.FieldInfo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wicket.okrapp.base.service.MOmsAccountPlanBillService;
import com.wicket.okrapp.common.exception.BizException;
import com.wicket.okrapp.common.util.CommonFunctionHelper;
import com.wicket.okrapp.dal.mapper.mbg.OmsAccountPlanBillMapper;
import com.wicket.okrapp.dal.po.mbg.OmsAccountPlanBill;
import com.wicket.okrapp.base.service.dto.req.*;
//import com.wicket.okrapp.base.service.dto.res.*;

import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;

import java.util.*;
import java.util.stream.Collectors;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author ：
 * @since 2022/1/19 15:39
 *
 *
 * @version 1.0
 */
@Service
public class MOmsAccountPlanBillServiceImpl
  extends ServiceImpl<OmsAccountPlanBillMapper, OmsAccountPlanBill>
  implements MOmsAccountPlanBillService {

  @Autowired
  OmsAccountPlanBillMapper omsAccountPlanBillMapper;
/**
   * 3-9-02批量增规划费用账单[2854]
   * gen by moon at 8/28/2022, 4:28:59 PM
   */
 @Trace(operationName = "3-9-02批量增规划费用账单")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  batchAddAccountPlanBill(List<OmsAccountPlanBill> omsAccountPlanBill) {
     
      if(omsAccountPlanBill==null || omsAccountPlanBill.size()==0){
        return false;
      }
      
      return super.saveBatch(omsAccountPlanBill.stream().map(item->{
       
          return item;
      }).collect(Collectors.toList()));
  }
/**
   * 3-9-02批量查询规划费用账单[3257]
   * gen by moon at 8/28/2022, 4:29:00 PM
   */
 @Trace(operationName = "3-9-02批量查询规划费用账单")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<OmsAccountPlanBill>  batchQueryAccountPlanBill(BatchQueryAccountPlanBillReq reqDto) {
     
        try {
            QueryWrapper<OmsAccountPlanBill> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
reqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID
reqDto.setAppId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecAppId());//CURRENT_APPID
            if(reqDto.getAccountPlanBillList()==null || reqDto.getAccountPlanBillList().isEmpty()){
                    return new ArrayList<>();
                }
        queryWrapper.in("plan_account_id", reqDto.getAccountPlanBillList());
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsAccountPlanBill.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsAccountPlanBill.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsAccountPlanBill.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);
            
            return ((List<OmsAccountPlanBill>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }
/**
   * 3-9-02批量删规划费用账单[3258]
   * gen by moon at 8/28/2022, 4:29:00 PM
   */
 @Trace(operationName = "3-9-02批量删规划费用账单")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  batchDeleteAccountPlanBill(List<String> reqDto) {
     
          if(reqDto==null || reqDto.size()==0){
            return false;
          }
          
          return super.removeByIds(reqDto);
  }

}

